package parts.renderer
{
	import flash.events.Event;
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	
	import mx.containers.VBox;
	import mx.controls.Label;
	import mx.controls.ProgressBar;
	import mx.controls.ProgressBarMode;
	
	public class ChargementBox extends VBox
	{
		private var currentCount_ : int;
		private var totalCount_ : int;
		
		private var titleLabel_ : Label;
		private var progressBar_ : ProgressBar;
		
		private var fadeTimer_ : Timer;
		
		public function ChargementBox()
		{
			
		}
		
		public function get totalCount() : int
		{
			return totalCount_;
		}
		
		public function set totalCount(value : int) : void
		{
			totalCount_ = value;
		}
		
		public function set progressLabel(value : String) : void
		{
			progressBar_.label = value;
			progressBar_.setProgress(currentCount_, totalCount_);
			
			currentCount_++;
		}
		
		
		public function setSubLabel(value : String) : void
		{
			progressBar_.label = value;
		}
		
		protected override function createChildren() : void
		{
			super.createChildren();
			
			titleLabel_ = new Label();
			titleLabel_.text = "Lushu Spritesheet Editor";
			titleLabel_.width = 195;
			titleLabel_.height = 30;
			titleLabel_.setStyle("textAlign", "center");
			titleLabel_.setStyle("fontWeight", "bold");
			titleLabel_.setStyle("fontFamily", "Arial");
			titleLabel_.setStyle("fontSize", "11");
			addChild(titleLabel_);
			
			progressBar_ = new ProgressBar();
			progressBar_.width = 195;
			progressBar_.height = 20;
			progressBar_.mode = ProgressBarMode.MANUAL;
			addChild(progressBar_);
		}
		
		
		public function fadeAway() : void
		{
			fadeTimer_ = new Timer(50, 10);
			fadeTimer_.addEventListener(TimerEvent.TIMER, onFadeTimer);
			fadeTimer_.addEventListener(TimerEvent.TIMER_COMPLETE, onFadeTimerComplete);
			fadeTimer_.start();
		}
		
		private function onFadeTimer(e : TimerEvent) : void
		{
			this.alpha -= 0.1;
		}
		
		private function onFadeTimerComplete(e : TimerEvent) : void
		{
			this.dispatchEvent(new Event("boxRemoved"));
		}
	}
}